/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.home.table.editor;

import com.home.common.Constants;
import java.awt.Component;
import javax.swing.*;
import javax.swing.table.*;

/**
 *
 * @author vi
 */
public class AlignmentCenterTableScorecardHeaderCellRenderer implements TableCellRenderer {

    private final TableCellRenderer wrappedRenderer;
    private final JLabel label;

    public AlignmentCenterTableScorecardHeaderCellRenderer(TableCellRenderer wrappedRenderer) {
        if (!(wrappedRenderer instanceof JLabel)) {
            throw new IllegalArgumentException("The supplied renderer must inherit from JLabel");
        }
        this.wrappedRenderer = wrappedRenderer;
        this.label = (JLabel) wrappedRenderer;
    }

    @Override
    public Component getTableCellRendererComponent(JTable table, Object value,
            boolean isSelected, boolean hasFocus, int row, int column) {
        wrappedRenderer.getTableCellRendererComponent(table, value,
                isSelected, hasFocus, row, column);
        if (column == Constants.TABLE_SCORECARD_DETAILS_COLUMN_EVALUATE_SCORE 
                || column == Constants.TABLE_SCORECARD_DETAILS_COLUMN_CALCULATED_SCORE) {
            label.setHorizontalAlignment(JLabel.CENTER);
        }
        return label;
    }
}
